<template>
  <s-layout class="set-wrap" title="立即兑换" :bgStyle="{ color: '#FFF' }">
    <!-- <s-empty
      v-if="state.list.length === 0 && !state.loading"
      text="暂无立即兑换"
      icon="/static/collect-empty.png"
    /> -->
    <!-- 页面开始 -->
    <!-- 页面开始 -->
    <!-- 页面开始 -->
    <view class="flex flex-col p-4">
      <view class="flex gap-4 justify-between items-center py-1 border-b">
        <view class="text-[.9375rem] text-[#333333]">证券账户： </view>
        <uni-easyinput v-model="state.account" placeholder="请输入证券账户" type="text" :inputBorder="false"> </uni-easyinput>
      </view>
      <view class="flex gap-4 justify-between items-center border-b" py-1>
        <view class="text-[.9375rem] text-[#333333]">账户姓名： </view>
        <uni-easyinput v-model="state.name" placeholder="请输入证券姓名" type="text" :inputBorder="false"> </uni-easyinput>
      </view>
      <view class="flex items-center py-3 text-[.9375rem] text-[#333333]">
        <view> 可兑换数量： </view>
        <view class="text-[#EC3C3C]"> {{ state.list.gp }} </view>
      </view>
      <view class="flex overflow-hidden items-center px-3 py-3 rounded-md border">
        <input placeholder="请输入兑换数量" v-model="state.num" class="text-[.9375rem]" />
      </view>
      <view class="flex items-center px-4 py-3 mt-3 bg-[#FFF7F7] rounded-lg">
        <u-icon name="info-circle" color="#EC3C3C" size="16"></u-icon>
        <text class="ml-2 text-[.875rem] text-[#EC3C3C]">温馨提示：只能全部兑换，无法部分兑换</text>
      </view>
    </view>
    <view class="fixed right-0 bottom-0 left-0 p-4 bg-white">
      <u-button type="primary" size="medium" @click="confirmExchange" class="overflow-hidden rounded-lg">确认兑换</u-button>
    </view>
  </s-layout>
</template>

<script setup>
  import sheep from '@/sheep';

  const state = ref({
    list: {},
    loading: true,
    account: '',
    name: '',
    num: '',
  });
  gpInfo();
  function gpInfo(params) {
    let obj = {};
    sheep.$api.yy.gpInfo(obj).then((res) => {
      state.value.list = res.data;
    });
  }
  function confirmExchange() {
    // if (!state.value.list.gp) {
    //   uni.showToast({
    //     title: '可兑换数量为空',
    //     icon: 'none',
    //   });
    //   return;
    // }
    // gpWithdraw
    let obj = {
      account: state.value.account,
      name: state.value.name,
      num: state.value.num,
    };
    sheep.$api.yy.gpWithdraw(obj).then((res) => {
      if (res.code == 1) {
        uni.showToast({
          title: '兑换成功',
          icon: 'none',
        });
        setTimeout(() => {
          gpInfo();
          state.value.account = '';
          state.value.name = '';
          state.value.num = '';
        }, 500);
      }
    });
  }
</script>

<style lang="scss" scoped></style>
